package it.polimi.traveldream.beans;

import it.polimi.traveldream.dto.TransportDTO;

import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import org.primefaces.context.RequestContext;

@ManagedBean(name = "transportDialogBean")
@ViewScoped
public class TransportDialogBean {

	private String origin;

	private String destination;

	private Integer selected;

	public TransportDialogBean() {
	}

	@PostConstruct
	public void init() {
		Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
				.getRequestParameterMap();

		this.origin = params.get("origin");

		this.destination = params.get("destination");

		String selected = params.get("selected");
		if (selected != null && !selected.isEmpty()) {
			this.selected = Integer.valueOf(selected);
		}
	}

	public String getOrigin() {
		return this.origin;
	}

	public void setOrigin(String origin) {
		this.origin = origin;
	}

	public String getDestination() {
		return this.destination;
	}

	public void setDestination(String destination) {
		this.destination = destination;
	}

	public Integer getSelected() {
		return this.selected;
	}

	public void setSelected(Integer selected) {
		this.selected = selected;
	}

	public String select(TransportDTO transport) {
		RequestContext.getCurrentInstance().closeDialog(transport);
		return null;
	}
}
